import { $get } from '@js/request'
import { strToNum } from '@src/assets/js/tool'

export async function initListRequest (caseid, friendid, condition, pageSize = 20) {
  const res = await $get('/api/xapc/xd/imessage/getFriendMessage', {
    caseid,
    friendid,
    condition: JSON.stringify(condition),
    page_size: pageSize,
    current: 1
  })
  const l = res.data.list
  l.forEach(li => {
    li.create_datetime = strToNum(li.create_datetime)
    li.delivered_datetime = strToNum(li.delivered_datetime)
    li.read_datetime = strToNum(li.read_datetime)
    if (typeof li.content === 'string') {
      li.content = li.content.replace(/\n/g, '<br/>')
    }
  })
  l.sort((a, b) => a.delivered_datetime - b.delivered_datetime)
  return res.data
}
